$(function(){

	let date = (new Date()).getFullYear()
	let chooseDateHtml = '<option></option>'
	for(let year = date-10; year <= date; year++){
		chooseDateHtml += `<option>${year}</option>`
	}
	$('#choseYear_projectManage').html(chooseDateHtml)



	$.ajax({
		url:'/Admin/Project/getPros',
		type:'get',
		success:function(data){
			let datas = data.data
			if(datas.length>0){
				let html = ``
				for(let key of datas){
					// console.log(key)
					html += `
						<li data-id='${key.id}' data-name='${key.pro_name}' data-num='${key.pro_sn}'>
					        <div class="pro_list_top">
					            <p class="pro_list_top_proName">${key.pro_name}</p>
					            <p class="pro_list_top_proNum">项目编号：${key.pro_sn}</p>
					        </div>
					        <div class="pro_list_middle">
					        `
					        if(key.pro_method=='自主研发'){
					        	html += `
					        		<div class="pro_list_middle_bigO zz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='委托研发'){
								html += `
					        		<div class="pro_list_middle_bigO wt">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='集中研发'){
								html += `
					        		<div class="pro_list_middle_bigO jz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='合作研发'){
								html += `
					        		<div class="pro_list_middle_bigO hz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }
				            html += `
					            <ul class="pro_list_middle_info">
					                <li>开始时间：${key.pro_start||'-'}</li>
					                <li>结束时间：${key.pro_end||'-'}</li>
					                <li>经费预算：${key.pro_total||'-'}</li>
					            </ul>
					        </div>
					    </li>
					`
				}
				$('.pro_list').html(html)
			}
		}
	})


	$('#tap_list').on('click','a',function(e){
		e.preventDefault()
		let is_approve = $(this).attr('href')
		$(this).addClass('active')
		$(this).parent().siblings().children().removeClass('active')
		$.ajax({
			url:'/Admin/Project/getPros',
			type:'get',
			data:{
				is_approve:is_approve
			},
			success:function(data){
				let datas = data.data
				let html = ``
				for(let key of datas){
					html += `
						<li data-id='${key.id}' data-name='${key.pro_name}' data-num='${key.pro_sn}'>
					        <div class="pro_list_top">
					            <p class="pro_list_top_proName">${key.pro_name}</p>
					            <p class="pro_list_top_proNum">项目编号：${key.pro_sn}</p>
					        </div>
					        <div class="pro_list_middle">
					        `
					        if(key.pro_method=='自主研发'){
					        	html += `
					        		<div class="pro_list_middle_bigO zz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='委托研发'){
								html += `
					        		<div class="pro_list_middle_bigO wt">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='集中研发'){
								html += `
					        		<div class="pro_list_middle_bigO jz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='合作研发'){
								html += `
					        		<div class="pro_list_middle_bigO hz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }
				            html += `
					            <ul class="pro_list_middle_info">
					                <li>开始时间：${key.pro_start||'-'}</li>
					                <li>结束时间：${key.pro_end||'-'}</li>
					                <li>经费预算：${key.pro_total||'-'}</li>
					            </ul>
					        </div>
					    </li>
					`
				}
				$('.pro_list').html(html)
			}
		})
	})


     //搜索
     $('#query_btn').click(function(){
     	let time = $('#choseYear_projectManage').find('option:selected').text()
     	let pro_info = $('#query_input').val()
     	$.ajax({
     		url:'/Admin/Project/getPros',
     		type:'get',
     		data:{
     			time:time,
     			pro_info:pro_info
     		},
     		success:function(data){
				let datas = data.data
				let html = ``
				for(let key of datas){
					html += `
						<li data-id='${key.id}' data-name='${key.pro_name}' data-num='${key.pro_sn}'>
					        <div class="pro_list_top">
					            <p class="pro_list_top_proName">${key.pro_name}</p>
					            <p class="pro_list_top_proNum">项目编号：${key.pro_sn}</p>
					        </div>
					        <div class="pro_list_middle">
					        `
					        if(key.pro_method=='自主研发'){
					        	html += `
					        		<div class="pro_list_middle_bigO zz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='委托研发'){
								html += `
					        		<div class="pro_list_middle_bigO wt">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='集中研发'){
								html += `
					        		<div class="pro_list_middle_bigO jz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }else if(key.pro_method=='合作研发'){
								html += `
					        		<div class="pro_list_middle_bigO hz">
						                <div class="pro_list_middle_smallO"><span class="pro_list_middle_O_text">${key.pro_method}</span></div>
						            </div>
					        	`
					        }
				            html += `
					            <ul class="pro_list_middle_info">
					                <li>开始时间：${key.pro_start||'-'}</li>
					                <li>结束时间：${key.pro_end||'-'}</li>
					                <li>经费预算：${key.pro_total||'-'}</li>
					            </ul>
					        </div>
					    </li>
					`
				}
				$('.pro_list').html(html)
     		}
     	})
     })

	$('.pro_list').on('click','li',function(e){
		// console.log($(this).attr('data-id'))
		let id = $(this).attr('data-id')
		let name = $(this).attr('data-name')
		let num = $(this).attr('data-num')
		$.ajax({
			url:'/Admin/ProcessIndex/session_pro',
			type:'get',
			data:{
				id:id,
				pro_name:name,
				pao_sn:num
			},
			success:function(data){
				if(data.code==1){
					window.location.href='/admin/ProStaff/index'
				}
			}
		})
	})


    //当点击区域不在导入弹框中时则关闭弹框
    $(document).click(function(e){
        let $this = $(e.target);
        if($this.attr('id') == 'choose' && $this.parent().attr('id') != 'choose'){
            $('#choose').removeClass('active');
            window.sessionStorage['pro_id'] = ''
            window.sessionStorage['choose_year'] = ''
        }
    })

    // 弹出来的小框框
    function tipShow(){
        window.tipBox = setTimeout(function(){
            $('#yz_modal').removeClass('active')
            clearTimeout(tipBox)
        },2000)
    }
	
})